#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time:2020/10/30 9:14 下午
# @Author:boyizhang
from sqlalchemy import Column,String,Integer,Float,DateTime,ForeignKey
from app.database import Base
from sqlalchemy.orm import relationship
from datetime import datetime
class Project(Base):
    '''
    项目
    '''
    __tablename__ = 'project'
    project_id = Column(Integer,primary_key=True,autoincrement=True)
    project_name = Column(String)
    address = Column(String)
    boss_name = Column(String)
    contacts = Column(String)
    start_time = Column(DateTime,default=datetime.now())
    end_time = Column(DateTime,nullable=True)
    total_fees = Column(Float,nullable=True)
    wages = Column(Float,nullable=True)
    decription = Column(String)
    status = Column(String)
    is_delete = Column(Integer,default=0)

    def __repr__(self):
        pass

class User(Base):
    '''
    用户
    '''
    __tablename__ = 'user'
    user_id = Column(Integer,primary_key=True,autoincrement=True)
    user_name = Column(String)
    type_id = Column(Integer,ForeignKey('userType.type_id'))
    phone_number = Column(String)
    status = Column(Integer,default=0)

    userType = relationship("UserType",backref='user')


class UserType(Base):
    '''
    用户类型
    '''
    __tablename__ = 'userType'
    type_id = Column(Integer,primary_key=True,autoincrement=True)
    type_name = Column(String)
    rate = Column(Float)
    # user = relationship("User",backref = 'userType')

class WordRecord(Base):
    # 多对一
    '''
    工时记录
    '''
    __tablename__ = 'wordRecord'
    id = Column(Integer,primary_key=True,autoincrement=True)
    project_id = Column(Integer,ForeignKey('project.project_id'))
    user_id = Column(Integer,ForeignKey('user.user_id'))
    create_time = Column(DateTime,default=datetime.now())
    working_hours = Column(Float)
    decription = Column(String)

    project = relationship("Project",backref="wordRecord")
    user = relationship("User", backref='wordRecord')


class FeesRecord(Base):
    '''
    伙食记录
    '''
    __tablename__ = 'feesRecord'
    fees_id = Column(Integer,primary_key=True,autoincrement=True)
    project_id = Column(Integer,ForeignKey('project.project_id'))
    user_id = Column(Integer)
    create_time = Column(DateTime,default=datetime.now())
    cost = Column(Float)
    cost_way = Column(String)
    remaining_money = Column(Float)
    decription = Column(String)

    project = relationship("Project",backref='feesRecord')



class ChangeLog(Base):
    __tablename__='changelog'
    log_id = Column(Integer,primary_key=True,autoincrement=True)
    user_id = Column(Integer)
    create_time = Column(DateTime,default=datetime.now())
    operation = Column(String)
    before_change = Column(String)
    after_change = Column(String)
    decription = Column(String)
    #
    # user = relationship("User",backref = 'changelog')

